home *** CD-ROM | disk | FTP | other *** search
- #include "stdafx.h"
-
- cAudible::cAudible(cProperties *_orig)
- : cAnimatable(_orig)
- {
- sequence = 0;
- looped = FALSE;
- voice = 0;
- }
-
- cAudible::~cAudible()
- {
- stop_sound();
- }
-
- int cAudible::current_sound_finished()
- {
- if (voice == 0 || !sound_wait)
- return TRUE;
-
- DWORD pos;
-
- voice->GetCurrentPosition(&pos, 0);
-
- return pos == 0;
- }
-
- void cAudible::set_sound(cSound *sound)
- {
- // Handle no sound case or if game is not running
-
- if (no_sound || sound == 0 || end_game)
- return;
-
- // Allocate voice
-
- if (FAILED(DS->DuplicateSoundBuffer(sound->sample->dsb, &voice)))
- error("Unable to allocate sound buffer duplicate");
-
- // Set other parameters
-
- voice->SetCurrentPosition(1);
- voice->SetVolume(sound->volume);
- voice->SetPan(-2000 + 4000 * x / surface->w);
- voice->Play(0, 0, (sound->duration > 0 || sound->loop)? DSBPLAY_LOOPING:0);
-
- sound_wait = sound->duration > 0? sound->duration:MAXFIX;
- }
-
- void cAudible::kill_sound()
- {
- if (voice != 0)
- {
- voice->Stop();
- voice->Release();
- voice = 0;
- }
- }
-
- void cAudible::add_sound_to_sequence(cSound *sound)
- {
- if (sound_done() && y_on_screen())
- set_sound(sound);
- else
- new cContainer<cSound> (&sequence, sound);
- }
-
- void cAudible::add_soundsequence(cSoundSequence &seq, int _looped)
- {
- cSound *i;
-
- looped = _looped && seq.start_sound != seq.end_sound;
- looped_sound = seq;
-
- if (seq.start_sound == 0)
- return;
-
- for (i = seq.start_sound; i != 0 && i != seq.end_sound; i = (cSound *)i->next)
- add_sound_to_sequence(i);
-
- add_sound_to_sequence(i);
- }
-
- void cAudible::add_soundsequence(char *seq, int looped)
- {
- cSoundSequence s;
-
- orig->get_soundsequence(seq, s);
- add_soundsequence(s, looped);
- }
-
- int cAudible::control()
- {
- // Animate images
-
- cAnimatable::control();
-
- // Do sounds
-
- if (!no_sound && (voice != 0 || sequence != 0) && current_sound_finished())
- {
- // Kill old sound
-
- kill_sound();
-
- // Is there more?
-
- if (sequence != 0 && y_on_screen())
- {
- // Next sound
-
- set_sound(sequence->contents);
- delete(sequence);
-
- // Do looped animations
-
- if (sequence == 0 && looped)
- add_soundsequence(looped_sound, TRUE);
- }
- }
-
- return TRUE;
- }
-